import 'package:flutter/material.dart';
import 'package:play_android/com/zhihaoliang/base/BaseState.dart';
import 'package:play_android/com/zhihaoliang/const/AppStr.dart';
import 'package:play_android/com/zhihaoliang/http/HttpException.dart';
import 'package:play_android/com/zhihaoliang/play/find/model/TreeClass.dart';
import 'package:play_android/com/zhihaoliang/play/find/model/TreeItem.dart';
import 'package:play_android/com/zhihaoliang/play/home/view/ArticleItemPage.dart';
import 'package:play_android/com/zhihaoliang/play/presenter/TreePresenter.dart';
import 'package:play_android/com/zhihaoliang/widget/NoData.dart';
import 'package:flutter/scheduler.dart' show timeDilation;

import 'ArticleListPage.dart';

///  ***************************************************************************
///  分类列表的页面
///  ***************************************************************************

class ArticlesPage extends StatefulWidget {
  TreeClass _treeClass;

  ArticlesPage(this._treeClass);

  @override
  State<StatefulWidget> createState() {
    return _ArticlesPageState();
  }
}

class _ArticlesPageState extends State<ArticlesPage>
    with SingleTickerProviderStateMixin {
  TabController _tabController;

  List<Tab> _tabs = new List();

  @override
  void initState() {
    super.initState();

    print(widget._treeClass.children);
    widget._treeClass.children.forEach((item) {
      _tabs.add(Tab(text: item.name));
    });

    _tabController =
        TabController(length: widget._treeClass.children.length, vsync: this);
  }

  @override
  void dispose() {
    _tabController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    timeDilation = 1.0;

    return Scaffold(
        appBar: AppBar(
          title: Text(widget._treeClass.name),
        ),
        body: DefaultTabController(
          length: widget._treeClass.children.length,
          child: Scaffold(
              appBar: TabBar(
                isScrollable: true,
                controller: _tabController,
                labelColor: Theme.of(context).accentColor,
                unselectedLabelColor: Colors.black,
                indicatorColor: Theme.of(context).accentColor,
                tabs: _tabs,
              ),
              body: TabBarView(
                controller: _tabController,
                children: widget._treeClass.children.map((itemData) {
                  return ArticlesListPage(itemData.id.toString());
                }).toList(),
              )),
        ));
  }
}
